/**
 * 获取订单列表接口
 */

//引入Q模块
let Q = require('q');
//引入公共函数
let util = require('../../util');

//getOrderList接口入口文件
let index = function(getData, postData, config, redis, db) {
	let deferred = Q.defer();
	if(postData.year && postData.month && postData.day) {
		let timestamp = new Date(postData.year + '-' + postData.month + '-' + postData.day).getTime() / 1000;
		db.select('storeOrder', {
			timestamp: {
				$gte: timestamp,
				$lte: timestamp + 86400
			}
		}).then(function(orderList) {
			deferred.resolve(orderList);
		}, function() {
			//获取指定天的订单列表失败
			deferred.reject('-0177');
		});
	}
	else {
		//获取指定天的订单列表接口参数不足
		deferred.reject('-0176');
	}
	return deferred.promise;
}

//暴露接口
module.exports = {
	index: index
}